﻿using System.Web;

namespace Zapi.Start
{
    /// <summary>
    /// 返回404代码
    /// </summary>
    public class WebApiApplicationConfig
    {
        /// <summary>
        /// 404
        /// </summary>
        /// <param name="httpApplication"></param>
        public static void EndRequest(HttpApplication httpApplication)
        {
            if (httpApplication.Context.Request.HttpMethod == "OPTIONS")
            {
                httpApplication.Context.Response.StatusCode = 200;
            }
            if (httpApplication.Context.Response.StatusCode == 402 ||httpApplication.Context.Response.StatusCode == 403 || httpApplication.Context.Response.StatusCode == 404|| httpApplication.Context.Response.StatusCode == 405)
            {

                var sc = httpApplication.Context.Response.StatusCode;
                var msg = httpApplication.Context.Response.StatusDescription;
                httpApplication.Response.Clear();
                httpApplication.Response.ContentType = "application/json";
                httpApplication.Response.Write("${\"Code\":\"" + sc + "\",\"Msg\":\"" + msg + "\"}");
            }
        }
    }
}